<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- Copyright © 1988-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below).  A copy of the license is included in the section entitled
"GNU Free Documentation License".

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<title>Statements for C and C++ (GNU Compiler Collection (GCC) Internals)</title>

<meta name="description" content="Statements for C and C++ (GNU Compiler Collection (GCC) Internals)">
<meta name="keywords" content="Statements for C and C++ (GNU Compiler Collection (GCC) Internals)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="index.html" rel="start" title="Top">
<link href="Option-Index.html" rel="index" title="Option Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="C-and-C_002b_002b-Trees.html" rel="up" title="C and C++ Trees">
<link href="C_002b_002b-Expressions.html" rel="next" title="C++ Expressions">
<link href="Functions-for-C_002b_002b.html" rel="prev" title="Functions for C++">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.example {margin-left: 3.2em}
span.r {font-family: initial; font-weight: normal; font-style: normal}
span:hover a.copiable-link {visibility: visible}
-->
</style>


</head>

<body lang="en">
<div class="subsection-level-extent" id="Statements-for-C-and-C_002b_002b">
<div class="nav-panel">
<p>
Next: <a href="C_002b_002b-Expressions.html" accesskey="n" rel="next">C++ Expressions</a>, Previous: <a href="Functions-for-C_002b_002b.html" accesskey="p" rel="prev">Functions for C++</a>, Up: <a href="C-and-C_002b_002b-Trees.html" accesskey="u" rel="up">C and C++ Trees</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h4 class="subsection" id="Statements-for-C-and-C_002b_002b-1"><span>11.10.5 Statements for C and C++<a class="copiable-link" href="#Statements-for-C-and-C_002b_002b-1"> &para;</a></span></h4>
<a class="index-entry-id" id="index-statements-1"></a>
<a class="index-entry-id" id="index-BREAK_005fSTMT"></a>
<a class="index-entry-id" id="index-CLEANUP_005fSTMT"></a>
<a class="index-entry-id" id="index-CLEANUP_005fDECL"></a>
<a class="index-entry-id" id="index-CLEANUP_005fEXPR"></a>
<a class="index-entry-id" id="index-CONTINUE_005fSTMT"></a>
<a class="index-entry-id" id="index-DECL_005fSTMT"></a>
<a class="index-entry-id" id="index-DECL_005fSTMT_005fDECL"></a>
<a class="index-entry-id" id="index-DO_005fSTMT"></a>
<a class="index-entry-id" id="index-DO_005fBODY"></a>
<a class="index-entry-id" id="index-DO_005fCOND"></a>
<a class="index-entry-id" id="index-EMPTY_005fCLASS_005fEXPR"></a>
<a class="index-entry-id" id="index-EXPR_005fSTMT"></a>
<a class="index-entry-id" id="index-EXPR_005fSTMT_005fEXPR"></a>
<a class="index-entry-id" id="index-FOR_005fSTMT"></a>
<a class="index-entry-id" id="index-FOR_005fINIT_005fSTMT"></a>
<a class="index-entry-id" id="index-FOR_005fCOND"></a>
<a class="index-entry-id" id="index-FOR_005fEXPR"></a>
<a class="index-entry-id" id="index-FOR_005fBODY"></a>
<a class="index-entry-id" id="index-HANDLER"></a>
<a class="index-entry-id" id="index-IF_005fSTMT"></a>
<a class="index-entry-id" id="index-IF_005fCOND"></a>
<a class="index-entry-id" id="index-THEN_005fCLAUSE"></a>
<a class="index-entry-id" id="index-ELSE_005fCLAUSE"></a>
<a class="index-entry-id" id="index-RETURN_005fSTMT"></a>
<a class="index-entry-id" id="index-RETURN_005fEXPR"></a>
<a class="index-entry-id" id="index-SUBOBJECT"></a>
<a class="index-entry-id" id="index-SUBOBJECT_005fCLEANUP"></a>
<a class="index-entry-id" id="index-SWITCH_005fSTMT"></a>
<a class="index-entry-id" id="index-SWITCH_005fCOND"></a>
<a class="index-entry-id" id="index-SWITCH_005fBODY"></a>
<a class="index-entry-id" id="index-TRY_005fBLOCK"></a>
<a class="index-entry-id" id="index-TRY_005fSTMTS"></a>
<a class="index-entry-id" id="index-TRY_005fHANDLERS"></a>
<a class="index-entry-id" id="index-HANDLER_005fPARMS"></a>
<a class="index-entry-id" id="index-HANDLER_005fBODY"></a>
<a class="index-entry-id" id="index-USING_005fSTMT"></a>
<a class="index-entry-id" id="index-WHILE_005fSTMT"></a>
<a class="index-entry-id" id="index-WHILE_005fBODY"></a>
<a class="index-entry-id" id="index-WHILE_005fCOND"></a>

<p>A function that has a definition in the current translation unit has
a non-<code class="code">NULL</code> <code class="code">DECL_INITIAL</code>.  However, back ends should not make
use of the particular value given by <code class="code">DECL_INITIAL</code>.
</p>
<p>The <code class="code">DECL_SAVED_TREE</code> gives the complete body of the
function.
</p>
<p>There are tree nodes corresponding to all of the source-level
statement constructs, used within the C and C++ frontends.  These are
enumerated here, together with a list of the various macros that can
be used to obtain information about them.  There are a few macros that
can be used with all statements:
</p>
<dl class="ftable">
<dt><a id="index-STMT_005fIS_005fFULL_005fEXPR_005fP"></a><span><code class="code">STMT_IS_FULL_EXPR_P</code><a class="copiable-link" href="#index-STMT_005fIS_005fFULL_005fEXPR_005fP"> &para;</a></span></dt>
<dd><p>In C++, statements normally constitute &ldquo;full expressions&rdquo;; temporaries
created during a statement are destroyed when the statement is complete.
However, G++ sometimes represents expressions by statements; these
statements will not have <code class="code">STMT_IS_FULL_EXPR_P</code> set.  Temporaries
created during such statements should be destroyed when the innermost
enclosing statement with <code class="code">STMT_IS_FULL_EXPR_P</code> set is exited.
</p>
</dd>
</dl>

<p>Here is the list of the various statement nodes, and the macros used to
access them.  This documentation describes the use of these nodes in
non-template functions (including instantiations of template functions).
In template functions, the same nodes are used, but sometimes in
slightly different ways.
</p>
<p>Many of the statements have substatements.  For example, a <code class="code">while</code>
loop has a body, which is itself a statement.  If the substatement
is <code class="code">NULL_TREE</code>, it is considered equivalent to a statement
consisting of a single <code class="code">;</code>, i.e., an expression statement in which
the expression has been omitted.  A substatement may in fact be a list
of statements, connected via their <code class="code">TREE_CHAIN</code>s.  So, you should
always process the statement tree by looping over substatements, like
this:
</p><div class="example smallexample">
<pre class="example-preformatted">void process_stmt (stmt)
     tree stmt;
{
  while (stmt)
    {
      switch (TREE_CODE (stmt))
        {
        case IF_STMT:
          process_stmt (THEN_CLAUSE (stmt));
          /* <span class="r">More processing here.</span>  */
          break;

        ...
        }

      stmt = TREE_CHAIN (stmt);
    }
}
</pre></div>
<p>In other words, while the <code class="code">then</code> clause of an <code class="code">if</code> statement
in C++ can be only one statement (although that one statement may be a
compound statement), the intermediate representation sometimes uses
several statements chained together.
</p>
<dl class="table">
<dt><code class="code">BREAK_STMT</code></dt>
<dd>
<p>Used to represent a <code class="code">break</code> statement.  There are no additional
fields.
</p>
</dd>
<dt><code class="code">CLEANUP_STMT</code></dt>
<dd>
<p>Used to represent an action that should take place upon exit from the
enclosing scope.  Typically, these actions are calls to destructors for
local objects, but back ends cannot rely on this fact.  If these nodes
are in fact representing such destructors, <code class="code">CLEANUP_DECL</code> will be
the <code class="code">VAR_DECL</code> destroyed.  Otherwise, <code class="code">CLEANUP_DECL</code> will be
<code class="code">NULL_TREE</code>.  In any case, the <code class="code">CLEANUP_EXPR</code> is the
expression to execute.  The cleanups executed on exit from a scope
should be run in the reverse order of the order in which the associated
<code class="code">CLEANUP_STMT</code>s were encountered.
</p>
</dd>
<dt><code class="code">CONTINUE_STMT</code></dt>
<dd>
<p>Used to represent a <code class="code">continue</code> statement.  There are no additional
fields.
</p>
</dd>
<dt><code class="code">CTOR_STMT</code></dt>
<dd>
<p>Used to mark the beginning (if <code class="code">CTOR_BEGIN_P</code> holds) or end (if
<code class="code">CTOR_END_P</code> holds of the main body of a constructor.  See also
<code class="code">SUBOBJECT</code> for more information on how to use these nodes.
</p>
</dd>
<dt><code class="code">DO_STMT</code></dt>
<dd>
<p>Used to represent a <code class="code">do</code> loop.  The body of the loop is given by
<code class="code">DO_BODY</code> while the termination condition for the loop is given by
<code class="code">DO_COND</code>.  The condition for a <code class="code">do</code>-statement is always an
expression.
</p>
</dd>
<dt><code class="code">EMPTY_CLASS_EXPR</code></dt>
<dd>
<p>Used to represent a temporary object of a class with no data whose
address is never taken.  (All such objects are interchangeable.)  The
<code class="code">TREE_TYPE</code> represents the type of the object.
</p>
</dd>
<dt><code class="code">EXPR_STMT</code></dt>
<dd>
<p>Used to represent an expression statement.  Use <code class="code">EXPR_STMT_EXPR</code> to
obtain the expression.
</p>
</dd>
<dt><code class="code">FOR_STMT</code></dt>
<dd>
<p>Used to represent a <code class="code">for</code> statement.  The <code class="code">FOR_INIT_STMT</code> is
the initialization statement for the loop.  The <code class="code">FOR_COND</code> is the
termination condition.  The <code class="code">FOR_EXPR</code> is the expression executed
right before the <code class="code">FOR_COND</code> on each loop iteration; often, this
expression increments a counter.  The body of the loop is given by
<code class="code">FOR_BODY</code>.  <code class="code">FOR_SCOPE</code> holds the scope of the <code class="code">for</code>
statement (used in the C++ front end only).  Note that
<code class="code">FOR_INIT_STMT</code> and <code class="code">FOR_BODY</code> return statements, while
<code class="code">FOR_COND</code> and <code class="code">FOR_EXPR</code> return expressions.
</p>
</dd>
<dt><code class="code">HANDLER</code></dt>
<dd>
<p>Used to represent a C++ <code class="code">catch</code> block.  The <code class="code">HANDLER_TYPE</code>
is the type of exception that will be caught by this handler; it is
equal (by pointer equality) to <code class="code">NULL</code> if this handler is for all
types.  <code class="code">HANDLER_PARMS</code> is the <code class="code">DECL_STMT</code> for the catch
parameter, and <code class="code">HANDLER_BODY</code> is the code for the block itself.
</p>
</dd>
<dt><code class="code">IF_STMT</code></dt>
<dd>
<p>Used to represent an <code class="code">if</code> statement.  The <code class="code">IF_COND</code> is the
expression.
</p>
<p>If the condition is a <code class="code">TREE_LIST</code>, then the <code class="code">TREE_PURPOSE</code> is
a statement (usually a <code class="code">DECL_STMT</code>).  Each time the condition is
evaluated, the statement should be executed.  Then, the
<code class="code">TREE_VALUE</code> should be used as the conditional expression itself.
This representation is used to handle C++ code like this:
</p>
<div class="example smallexample">
<pre class="example-preformatted">if (int i = 7) ...
</pre></div>

<p>where there is a new local variable (or variables) declared within the
condition.
</p>
<p>The <code class="code">THEN_CLAUSE</code> represents the statement given by the <code class="code">then</code>
condition, while the <code class="code">ELSE_CLAUSE</code> represents the statement given
by the <code class="code">else</code> condition.
</p>
<p>C++ distinguishes between this and <code class="code">COND_EXPR</code> for handling templates.
</p>
</dd>
<dt><code class="code">SUBOBJECT</code></dt>
<dd>
<p>In a constructor, these nodes are used to mark the point at which a
subobject of <code class="code">this</code> is fully constructed.  If, after this point, an
exception is thrown before a <code class="code">CTOR_STMT</code> with <code class="code">CTOR_END_P</code> set
is encountered, the <code class="code">SUBOBJECT_CLEANUP</code> must be executed.  The
cleanups must be executed in the reverse order in which they appear.
</p>
</dd>
<dt><code class="code">SWITCH_STMT</code></dt>
<dd>
<p>Used to represent a <code class="code">switch</code> statement.  The <code class="code">SWITCH_STMT_COND</code>
is the expression on which the switch is occurring.  See the documentation
for an <code class="code">IF_STMT</code> for more information on the representation used
for the condition.  The <code class="code">SWITCH_STMT_BODY</code> is the body of the switch
statement.   The <code class="code">SWITCH_STMT_TYPE</code> is the original type of switch
expression as given in the source, before any compiler conversions.
The <code class="code">SWITCH_STMT_SCOPE</code> is the statement scope (used in the
C++ front end only).
</p>
<p>There are also two boolean flags used with <code class="code">SWITCH_STMT</code>.
<code class="code">SWITCH_STMT_ALL_CASES_P</code> is true if the switch includes a default label
or the case label ranges cover all possible values of the condition
expression.  <code class="code">SWITCH_STMT_NO_BREAK_P</code> is true if there are no
<code class="code">break</code> statements in the switch.
</p>
</dd>
<dt><code class="code">TRY_BLOCK</code></dt>
<dd><p>Used to represent a <code class="code">try</code> block.  The body of the try block is
given by <code class="code">TRY_STMTS</code>.  Each of the catch blocks is a <code class="code">HANDLER</code>
node.  The first handler is given by <code class="code">TRY_HANDLERS</code>.  Subsequent
handlers are obtained by following the <code class="code">TREE_CHAIN</code> link from one
handler to the next.  The body of the handler is given by
<code class="code">HANDLER_BODY</code>.
</p>
<p>If <code class="code">CLEANUP_P</code> holds of the <code class="code">TRY_BLOCK</code>, then the
<code class="code">TRY_HANDLERS</code> will not be a <code class="code">HANDLER</code> node.  Instead, it will
be an expression that should be executed if an exception is thrown in
the try block.  It must rethrow the exception after executing that code.
And, if an exception is thrown while the expression is executing,
<code class="code">terminate</code> must be called.
</p>
</dd>
<dt><code class="code">USING_STMT</code></dt>
<dd><p>Used to represent a <code class="code">using</code> directive.  The namespace is given by
<code class="code">USING_STMT_NAMESPACE</code>, which will be a NAMESPACE_DECL.  This node
is needed inside template functions, to implement using directives
during instantiation.
</p>
</dd>
<dt><code class="code">WHILE_STMT</code></dt>
<dd>
<p>Used to represent a <code class="code">while</code> loop.  The <code class="code">WHILE_COND</code> is the
termination condition for the loop.  See the documentation for an
<code class="code">IF_STMT</code> for more information on the representation used for the
condition.
</p>
<p>The <code class="code">WHILE_BODY</code> is the body of the loop.
</p>
</dd>
</dl>

</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="C_002b_002b-Expressions.html">C++ Expressions</a>, Previous: <a href="Functions-for-C_002b_002b.html">Functions for C++</a>, Up: <a href="C-and-C_002b_002b-Trees.html">C and C++ Trees</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
